package com.ser02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletTest2")
public class ServletTest2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /*String method = request.getMethod();
        System.out.println(method);//GET   //POST*/

        /*String contextPath = request.getContextPath();
        System.out.println(contextPath);//获取的结果是项目的虚拟路径，此项目没有虚拟路径，所以为空白 */

        /*String servletPath = request.getServletPath();
        System.out.println(servletPath);//获取的结果为：/ServletTest2*/

        /*String requestURI = request.getRequestURI();
        System.out.println(requestURI);//获取的结果为：/ServletTest2*/

        /*StringBuffer requestURL = request.getRequestURL();
        System.out.println(requestURL);//获取的结果为: http://localhost/ServletTest2*/

        /*String queryString = request.getQueryString();
        System.out.println(queryString);//get获取的结果为: username=tom&password=123    //post获取的结果为: null
        String decode = URLDecoder.decode(queryString, "UTF-8");//传中文，浏览器会进行编码  //username=%E5%BC%A0%E4%B8%89&password=qqq
        System.out.println(decode);//username=张三&password=qqq*/

        /*String protocol = request.getProtocol();
        System.out.println(protocol);//获取的结果为: HTTP/1.1*/

        String remoteAddr = request.getRemoteAddr();
        System.out.println(remoteAddr);//获取的结果为: 0:0:0:0:0:0:0:1 (ipv6)

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
